<template>
  <el-dialog
      v-model="houseEditWinDialogVisible"
      title="修改仓库类型设置"
      width="60%"
      @close="handleClose"
      draggable
      center
  >
    <template #default>
      <el-form :model="house">
        <el-form-item label="仓库编码">
          <el-input v-model="house.houseEncode"/>
        </el-form-item>
        <el-form-item label="仓库名称">
          <el-input v-model="house.houseName"/>
        </el-form-item>
        <el-form-item label="位置">
          <el-input v-model="house.houseLocation"/>
        </el-form-item>
        <el-form-item label="面积">
          <el-input v-model="house.houseArea"/>
        </el-form-item>
        <el-form-item label="负责人">
          <el-input v-model="house.houseHead"/>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="house.houseRemark" type="textarea"/>
        </el-form-item>
      </el-form>
    </template>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="editHouseSubmit" type="primary">保存</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import {ref, watch} from "vue";
import {ElMessage} from "element-plus";
import houseRequest from "@/api/house.js";

const props = defineProps(['houseId']);
const emits = defineEmits(['cancelEdit','editComplete' ])
let houseEditWinDialogVisible = ref(false)
let house = ref({})


function cancel() {
  emits("cancelEdit");
  houseEditWinDialogVisible.value = false;
}

function handleClose() {
  emits("cancelEdit");
}

function loadHouseById() {
  houseRequest.selectById(props.houseId, res => {
    if (res.data) {
      house.value = res.data;
      houseEditWinDialogVisible.value = true;
    }
  })
}

function editHouseSubmit() {
  houseRequest.update(house.value, res => {
    if (res.code == 1) {
      ElMessage({
        type: "success",
        message: "编辑成功"
      });
      houseEditWinDialogVisible.value = false;
      // 触发编辑完成的事件
      emits('editComplete');
    } else {
      ElMessage({
        type: "warning",
        message: "编辑失败"
      });
    }
  })
}

watch(() => props.houseId, () => {
  loadHouseById();
});
</script>
<style scoped>

</style>